import QRequest from '@/service/index';
import { generateNameToLevel } from '@/config/constant';
import {
    ProcessListPageResponse,
    ProcessListPageParams,
    ProcessListModal,
    ProcedurePageResponse,
    ProcedurePageParams,
    MaterialChooseVO,
    MaterialListPageResponse
} from './model/type';

/**
 * @:获取工艺路线列表
 * @param {ProcessListPageParams} params
 * @return {*}
 */
export const doGetProcessList = (params: ProcessListPageParams) => {
    return QRequest.get<ProcessListPageResponse>(`/process/route/select/page`, {
        params
    });
};

/**
 * @:获取工艺路线详情
 * @return {*}
 */
export const doGetProcessDetail = (id: number | string) => {
    return QRequest.get<ProcessListModal>(`/process/route/detail?id=${id}`, {
        headers: {
            loadingTarget: `#${generateNameToLevel('4')}`
        }
    });
};

/**
 * @:获取工序变化之后的工艺路线详情
 * @return {*}
 */
export const doGetProcessDetailChange = (id: number | string) => {
    return QRequest.get<ProcessListModal>(`/process/route/detail/change?id=${id}`, {
        headers: {
            loadingTarget: `#${generateNameToLevel('4')}`
        }
    });
};

/**
 * @: 新增工艺路线列表
 * @param {ProcessListModal} data
 * @return {*}
 */
export const doAddProcess = (data: ProcessListModal) => {
    return QRequest.post(`/process/route/save`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 修改工艺路线列表
 * @param {ProcessListModal} data
 * @return {*}
 */
export const doEditProcess = (data: ProcessListModal) => {
    return QRequest.put(`/process/route/update`, data, {
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @: 删除工艺路线
 * @param {number[]} params
 * @return {*}
 */
export const doDelProcessList = (data: number[]) => {
    return QRequest.delete(`/process/route/delete`, {
        data,
        headers: {
            hideLoading: 1
        }
    });
};

/**
 * @:分页查询工序列表
 * @param {ProcedurePageParams} params
 * @return {*}
 */
export const doGetProcedureList = (params: ProcedurePageParams) => {
    return QRequest.get<ProcedurePageResponse>(`/working/procedure/page`, {
        params,
        headers: {
            loadingTarget: `#${generateNameToLevel('2')}`
        }
    });
};

/**
 * @:工艺路线选择物料
 * @param {MaterialChooseVO} params
 * @return {*}
 */
export const doGetMaterialList = (params: MaterialChooseVO) => {
    return QRequest.get<MaterialListPageResponse>(`/process/route/choose/material`, {
        params,
        headers: {
            loadingTarget: `#${generateNameToLevel('3')}`
        }
    });
};
